<template>
  <!-- 页脚 -->
  <footer class="footer">
    <p>
      2019 - 2022 © Bay 已运行 {{ time.daysRound }} 天 {{ time.hoursRound }} 时
      {{ time.minutesRound }} 分 {{ time.seconds }} 秒
    </p>
  </footer>
</template>

<script>
export default {
  created() {
    setInterval(() => {
      this.getDuration();
    }, 1000);
  },
  data() {
    return {
      createTime: new Date("2022/04/30 12:00:00"),
      time: {
        daysRound: 0,
        hoursRound: 0,
        minutesRound: 0,
        seconds: 0,
      },
    };
  },
  methods: {
    getDuration() {
      const my_time = new Date().getTime() - this.createTime;
      var daysRound = Math.floor(my_time / 1000 / 60 / 60 / 24);
      var hoursRound = Math.floor(my_time / 1000 / 60 / 60 - 24 * daysRound);
      var minutesRound = Math.floor(
        my_time / 1000 / 60 - 24 * 60 * daysRound - 60 * hoursRound
      );
      var seconds = Math.floor(
        my_time / 1000 -
          24 * 60 * 60 * daysRound -
          60 * 60 * hoursRound -
          60 * minutesRound
      );
      this.time = { daysRound, hoursRound, minutesRound, seconds };
    },
  },
};
</script>

<style scoped>
footer {
  padding: 10px;
  text-align: center;
}
</style>
